import 'package:flutter/material.dart';
import "package:get/get.dart";

import '../../../components/appbar_widget/appbar_widget.dart';
import '../../../components/loading/svg_loading.dart';
import '../../../components/status/not_network.dart';
import '../../../config/global_config.dart';
import '../../../controller/network/network_ctrl.dart';
import '../../../router/router.dart';
import '../../../utils/screenutil/fit.dart';
import 'components/info_list.dart';
import 'components/none_monitoring_facility.dart';
import 'components/none_video.dart';
import 'components/record.dart';
import 'components/run_table.dart';
import 'components/video_stream.dart';
import 'ctrl/info_ctrl.dart';
import 'ctrl/lift_details_ctrl.dart';
import 'ctrl/video_ctrl.dart';

class LiftDetails extends StatelessWidget {
  // 导入控制器
  final ldCtrl = Get.put(LiftDetailsCtrl());
  final videoCtrl = Get.put(VideoCtrl());
  final infoCtrl = Get.put(InfoCtrl());
  final _nc = Get.find<NetworkCtrl>();

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBarWidget("电梯详情", isMore: true).build(context),
      body: Obx(
        () => ldCtrl.isInitComplete.value
            ? Container(
                child: Stack(
                  children: [
                    SingleChildScrollView(
                      child: Container(
                        width: 640.f,
                        margin:
                            EdgeInsets.only(top: fit(_nc.topDistance.value)),
                        child: Column(
                          children: [
                            Container(
                              width: 640.f,
                              padding: EdgeInsets.symmetric(
                                vertical: 20.f,
                                horizontal: 20.f,
                              ),
                              color: Colors.white,
                              child: Row(
                                mainAxisAlignment:
                                    MainAxisAlignment.spaceBetween,
                                children: [
                                  Container(
                                    width: 400.f,
                                    child: Text(
                                      "${ldCtrl.dataSet["communityName"]}${ldCtrl.dataSet['liftLocation']}",
                                    ),
                                  ),
                                  InkWell(
                                    onTap: () => ldCtrl.switchInterfacePage(
                                      AppRoutes.LiftInfo,
                                      args: {
                                        "liftId": ldCtrl.dataSet["liftId"]
                                      },
                                    ),
                                    // onTap: () => null,
                                    child: Text(
                                      "查看电梯信息",
                                      style: TextStyle(
                                        fontSize: 22.f,
                                        color: GlobalConfig.theme,
                                      ),
                                    ),
                                  ),
                                ],
                              ),
                            ),

                            // 视频流
                            ldCtrl.isSupportVideo.value
                                ? VideoStream()
                                : NoneVideo(txt: ldCtrl.videoTipTxt.value),

                            // 信息列表
                            ldCtrl.isExistFacility.value
                                ? InfoList(top: 10.f)
                                : NoneMonitoringFacility(
                                    txt: ldCtrl.facilityTipTxt.value,
                                  ),

                            // 告警记录
                            Record(
                              "历史告警记录",
                              top: 10.f,
                              //isShowBadge: true,
                              callBack: () => ldCtrl.switchInterfacePage(
                                AppRoutes.HistoryAlarm,
                                args: {
                                  "elevatorId": ldCtrl.dataSet["liftId"],
                                  "communityName":
                                      ldCtrl.dataSet["communityName"],
                                  "liftLocation":
                                      ldCtrl.dataSet["liftLocation"],
                                },
                              ),
                            ),

                            // 维保记录
                            Record(
                              "维保记录",
                              top: 10.f,
                              callBack: () => ldCtrl.switchInterfacePage(
                                AppRoutes.Record,
                                args: {"elevatorId": ldCtrl.dataSet["liftId"]},
                              ),
                            ),

                            // 电梯运行统计
                            RunTable(top: 10.f),
                          ],
                        ),
                      ),
                    ),

                    // 网络状态
                    Positioned(top: 0, child: NotNetwork()),
                  ],
                ),
              )
            : SVGLoading(),
      ),
    );
  }
}
